package com.example.demo.controller;

import com.example.demo.common.domain.Room;
import com.example.demo.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class RoomController {
    @Autowired
    RoomService roomService;

    /**
     * @param model
     * @return
     */
    @RequestMapping("/room")
    public String room(Model model, String hotelId) {
        System.out.println("酒店id:"+hotelId);
        Integer HotelId = Integer.parseInt(hotelId);
        List<Room> roomList = roomService.roomList(HotelId);
        model.addAttribute("roomList", roomList);
        return "room";
    }

    @RequestMapping("/roominfo")
    public String roominfo(Model model, Integer id, HttpSession session) {
        Room room = roomService.roominfo(id);
        model.addAttribute("room", room);
        model.addAttribute("CheckIntime", session.getAttribute("CheckIntime"));
        model.addAttribute("CheckOuttime", session.getAttribute("CheckOuttime"));
        return "roominfo";
    }

}
